//  This file is part of Swordbible - http://www.swordwarrior.net
//  Copyright (C) 2003-2008 Manu Mital mitalmanu@hotmail.com

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


// SaveSearchResults.cpp : implementation file
//

#include "stdafx.h"
#include "SwordBible.h"
#include "SaveSearchResults.h"


// CSaveSearchResults dialog

IMPLEMENT_DYNAMIC(CSaveSearchResults, CDialog)

CSaveSearchResults::CSaveSearchResults(CWnd* pParent /*=NULL*/)
	: CDialog(CSaveSearchResults::IDD, pParent)
	
{

}

CSaveSearchResults::~CSaveSearchResults()
{
}

void CSaveSearchResults::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO_EXISTINGVL, ExistingVLcombo);
	DDX_Control(pDX, IDC_EDIT_VL_NAME, m_newListEditCtrl);
}


BEGIN_MESSAGE_MAP(CSaveSearchResults, CDialog)
	ON_BN_CLICKED(IDOK, &CSaveSearchResults::OnBnClickedOk)
	ON_BN_CLICKED(IDC_RADIO_NEWLIST, &CSaveSearchResults::OnRadioNewList)
	ON_BN_CLICKED(IDC_RADIO_EXISTINGLIST, &CSaveSearchResults::OnRadioExisting)
END_MESSAGE_MAP()


// CSaveSearchResults message handlers

void CSaveSearchResults::OnBnClickedOk()
{

	// check the radio button 1 (new verse list name)
    CButton* pWnd = (CButton *) GetDlgItem(IDC_RADIO_NEWLIST);

	// the user wants to add the search results to a new verse list
	if(pWnd->GetSafeHwnd() && pWnd->GetCheck() == TRUE)
	{
		m_newListEditCtrl.UpdateData(TRUE);
		m_newListEditCtrl.GetWindowText(listName);
	
		if(listName.GetLength() < 3 || listName.GetLength() > 25)
		{
			AfxMessageBox("List Name must be between 3 and 25 characters");
			listName = "";
			m_newListEditCtrl.SetWindowText("");
			return;

		}

		OnOK();
		return;
	}

	pWnd = (CButton *) GetDlgItem(IDC_RADIO_EXISTINGLIST);

	if(pWnd->GetSafeHwnd() && pWnd->GetCheck() == TRUE)
	{
		listName = "";
		ExistingVLcombo.GetLBText( ExistingVLcombo.GetCurSel(), listName);
		OnOK();
		return;


	}


	return;



	
	

	
}

BOOL CSaveSearchResults::OnInitDialog()
{
	CDialog::OnInitDialog();

	listName = "";

	int count = ListNames.GetCount();

	for(int i = 0; i < count; i++)
		ExistingVLcombo.AddString(ListNames.GetAt(i) );


	ExistingVLcombo.SetCurSel(0);

	// check the radio button 1 (new verse list name)
    CButton* pWnd = (CButton *) GetDlgItem(IDC_RADIO_NEWLIST);
	if(pWnd->GetSafeHwnd()) pWnd->SetCheck(TRUE);

	m_newListEditCtrl.EnableWindow(TRUE);
	ExistingVLcombo.EnableWindow(FALSE);


	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSaveSearchResults::OnRadioNewList()
{
	m_newListEditCtrl.SetWindowText("");  // clear the list name text in the edit control

	m_newListEditCtrl.EnableWindow(TRUE);
	ExistingVLcombo.EnableWindow(FALSE);
	
}

void CSaveSearchResults::OnRadioExisting()
{

	m_newListEditCtrl.SetWindowText("");   // clear the list name text in the edit control

	m_newListEditCtrl.EnableWindow(FALSE);
	ExistingVLcombo.EnableWindow(TRUE);

	
}
